using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FShop.BAL;

public partial class Controls_NewsDetail : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadNewsDetail();
            LoadOtherNews();
        }
    }

    private void LoadNewsDetail()
    {
        string sID=Request.QueryString["IDNew"];
        if (string.IsNullOrEmpty(sID) == false)
        {
            DataTable dt = new DataTable();
            dt = News_BAL.Get_NewsAsTable("News_ID=" + sID, "");
            frvNewDetail.DataSource = dt;
            frvNewDetail.DataBind();
            int hit = int.Parse(dt.Rows[0]["News_Hit"].ToString());
            hit = hit + 1;
            SqlDataSource1.UpdateCommand = "UPDATE [News] SET [News_Hit] = "+hit+" WHERE [News_ID] = "+sID+"";
            SqlDataSource1.Update();
        }
    }

    private void LoadOtherNews()
    {
        string sID = Request.QueryString["IDNew"];
         if (string.IsNullOrEmpty(sID) == false)
         {
             CollectionPager1.DataSource = News_BAL.GetList_News("News_ID <>"+sID);
             CollectionPager1.BindToControl = dtlOthersNews;
             dtlOthersNews.DataSource = CollectionPager1.DataSource;
             dtlOthersNews.DataBind();
         }
    }
    protected void dgrNewsDetail_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item)
        {
            Image img = (Image)e.Item.FindControl("Image1");
            if (img != null)
            {
                object obj = DataBinder.Eval(e.Item.DataItem, "News_Image");
                if (obj.ToString().Length > 0)                
                {
                    img.ImageUrl = "../Images/Product" +obj.ToString();
                }
                else
                {
                    img.ImageUrl = "../Images/NoImage.jpg";
                }
            }
        }
    }
    protected void frvNewDetail_DataBound(object sender, EventArgs e)
    {
        
    }
}
